<?php
namespace App\Http\Controllers\Xcx\Ywmall;

use App\Service\Xcx\Ywmall\ShopService;
use App\Utility\Upload;
use Illuminate\Http\Request;

class ShopController extends BaseController
{
    //店铺

    //列表
    public function index(Request $request)
    {
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('size', 6);
        $uid = $request->post('uid', 0);
        if (!$uid) {
            return $this->toJson(-2, '没有登录');
        }
        $res = ShopService::index($pages, $uid);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //修改
    public function modify(Request $request)
    {
        $id = $request->post('id', 0);
        $uid = $request->post('uid', 0);
        $pas['title'] = $request->post('title', '');
        $pas['head'] = $request->post('head', '');
        if ($id) {
            $res = ShopService::modify($id, $pas, $uid);
        } else {
            $res = ShopService::add($pas, $uid);
        }
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }

    //删除
    public function del(Request $request)
    {
        $id = $request->post('id', 0);
        $res = ShopService::del($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson();
    }
}